package org.niu.array;

import java.util.HashSet;
import java.util.Set;

public class MaxProduct {
    public int maxProduct(String[] words) {
        int ans = -1;
        for (int i = 0; i < words.length; i++) {
            for (int j = i+1; j < words.length; j++) {
                if(isValid(words[i],words[j])){
                    if(words[i].length()*words[j].length()>ans){
                        ans = words[i].length()*words[j].length();
                    }
                }
            }
        }
        return ans;
    }
    boolean isValid(String s1,String s2){
        Set<Character> set = new HashSet<>();
        for (char c : s1.toCharArray()) {
            set.add(c);
        }
        for (char c : s2.toCharArray()) {
            if(set.contains(c)){
                return false;
            }
        }
        return true;
    }
}
